package com.aps.server.parse.model.dto;

import com.aps.server.parse.ann.ExcelColumn;
import com.aps.server.parse.ann.ExcelParser;
import com.aps.server.parse.model.ExcelParseValidate;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-09-02  14:41
 **/
@ExcelParser
@Component("model-excel-import-dto-20250902")
@Data
public class TestExcelImportDto implements ExcelParseValidate<TestExcelImportDto> {

    private String a;

    @ExcelColumn(value = "日期" , defaultSampleValue = "19990101")
    private LocalDate date;

    @ExcelColumn(value = "日期时间" , defaultSampleValue = "19990101")
    private LocalDate dateTime;

    @ExcelColumn(value = "姓名")
    private String c;

    @ExcelColumn(value = "年龄")
    private int d;


    @Override
    public boolean validate() {
        if(d > 2 || StringUtils.isBlank(c)) {
            return false;
        }
        return true;
    }

    @Override
    public String createRowErrorDetails(TestExcelImportDto errorDetail, int rowNum){
        String sb = "第" + rowNum + "数据错误;";
        List<String> builderList = new ArrayList<>();
        builderList.add(sb);
        if(errorDetail.getD() > 2){
            builderList.add("年龄不能超过2");
        }
        if(StringUtils.isBlank(errorDetail.getC())){
            builderList.add("姓名不能为空");
        }
        return StringUtils.join(builderList, ";") ;
    }
}
